package com.zhy.sunmi.fragment.report;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.partner.tabtools.verticalTab.TabAdapter;
import com.partner.tabtools.verticalTab.TabView;
import com.partner.tabtools.verticalTab.VerticalTabLayout;
import com.zhy.sunmi.R;
import com.zhy.sunmi.fragment.sell.SubSellFragment;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class ReportFragment extends Fragment {
    List<String> tabsTitle = new ArrayList<>();
    List<Fragment> fragments = new ArrayList<>();
    ViewPager vpAllTags;
    FragmentPagerAdapter fragmentPagerAdapter;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_sell, container, false);
        initAdapter(view);
        return view;
    }

    private void initAdapter(View view) {
        TextView tv=view.findViewById(R.id.textView);
        tv.setText("Report");
        vpAllTags =view.findViewById(R.id.viewPager2);
        VerticalTabLayout verticalTabLayout=view.findViewById(R.id.verticalTabLayout2);
        tabsTitle = Arrays.asList(getString(R.string.reporting));
        for (String title : tabsTitle){
            Fragment fragment=new SubReportFragment();
            fragments.add(fragment);
        }


        fragmentPagerAdapter = new FragmentPagerAdapter(getChildFragmentManager()) {
            @NonNull
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }
        };

        vpAllTags.setAdapter(fragmentPagerAdapter);
        verticalTabLayout.setupWithViewPager(vpAllTags);

        TabAdapter adapter = new TabAdapter() {
            @Override
            public int getCount() {
                return tabsTitle.size();
            }

            @Override
            public TabView.TabBadge getBadge(int position) {
                return null;
            }

            @Override
            public TabView.TabIcon getIcon(int position) {
                return null;
            }

            @Override
            public TabView.TabTitle getTitle(int position) {

                return new TabView.TabTitle.Builder()
                        .setContent(tabsTitle.get(position))
                        .setTextSize(12)
                        .setTextColor(0xff6692b0,0xFF000000)
                        .build();
            }

            @Override
            public int getBackground(int position) {
//                if(position==2) return  R.color.white;
//                return R.color.white;
                return getResources().getColor(R.color.white2);
            }
        };

        verticalTabLayout.setTabAdapter(adapter);
    }


}